import {Component, OnInit} from '@angular/core';
import {NzModalRef, NzMessageService} from 'ng-zorro-antd';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {OtcBillService} from '@core/routes-services/otc-bill.service';
import {LEVEL_APPLICATION_OPTION, OTC_SHOP_CUS_ROLE} from '../../../../constant/dictionary';

@Component({
  selector: 'app-otc-bill-edit',
  templateUrl: './otc-bill-edit.component.html',
  styles: [`
    h2 {
      border-bottom: 1px solid #1890ff;
      color: #1890ff;
      padding-top: 10px;
    }
  `
  ]
})
export class OtcBillEditComponent implements OnInit {
  entity: any = {};
  validateForm: FormGroup;
  isLoading: boolean = true;
  statusOption: any [] = LEVEL_APPLICATION_OPTION;
  otcShopCusRole: any [] = OTC_SHOP_CUS_ROLE;
  imgs: any [] = []

  constructor(private fb: FormBuilder,
              private modal: NzModalRef,
              private otcBillService: OtcBillService,
              public message: NzMessageService,) {
  }

  ngOnInit(): void {
    console.log(this.entity)
    let that = this;
    this.imgs = this.entity.billImgs.split(',');
    setTimeout(function () {
      that.isLoading = false;
    }, 300)
    this.validateForm = this.fb.group({
      shopId: [this.entity.shopId, [Validators.required]],
    });
  }
  submitForm(): void {
    if (this.validateForm.invalid) {
      for (const i in this.validateForm.controls) {
        this.validateForm.controls[i].markAsDirty();
        this.validateForm.controls[i].updateValueAndValidity();
      }
    } else {

    }
  }

  picList: any [] = [];
  isShowPic: boolean = false;

  showPic(key) {
    this.picList = [];
    this.picList.push({imgKey: key});
    this.isShowPic = true
  }

  onPicClose(res) {
    this.isShowPic = res
    this.isShowPic = false
  }

  close() {
    this.modal.destroy();
  }
}
